package com.itheima.service.impl;

import com.itheima.dao.AccountDao;
import com.itheima.domain.Account;
import com.itheima.service.AccountService;
import org.apache.ibatis.transaction.Transaction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @description:
 * @author: 付益民
 * @create: 2020-09-25-20:06
 */
@Service
public class AccountServiceImpl implements AccountService {
    @Autowired
    private AccountDao accountDao;

    public int saveAccount(Account account) {
        return accountDao.saveAccount(account);
    }

    public int deleteAccount(String id) {
        return accountDao.deleteAccount(id);
    }

    public int updateAccount(Account account) {
        return accountDao.updateAccount(account);
    }

    public List<Account> findAll() {
        return accountDao.findAll();
    }

    public Account findById(String id) {
        return accountDao.findById(id);
    }

    public int sendMoney(Account account1, Account account2, Double money) {
        int result=-1;
        try {
            account1.setMoney(account1.getMoney() + money);
            account2.setMoney(account2.getMoney() - money);
            return 1;
        } catch (Exception e) {
            return result;
        }
    }
}
